import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'dart:async';
import 'dart:async';
import 'dart:async';

class AlertDialogDemo extends StatefulWidget {
  @override
  _AlertDialogDemoState createState() => _AlertDialogDemoState();
}
enum Action{
  OK,CANCEL
}
class _AlertDialogDemoState extends State<AlertDialogDemo> {
  String _chonse='n';
_open() async{
  final option= await  showDialog(
      barrierDismissible: false,
        context: context,
        builder: (BuildContext context) {
          return AlertDialog(
            title: Text('alert'),
            content: Text('about this?'),
            actions: [
              TextButton(
                onPressed: () {
                  Navigator.pop(context,Action.CANCEL);
                },
                child: Text('取消'),
              ),
              TextButton(
                onPressed: () {
                  Navigator.pop(context,Action.OK);
                },
                child: Text('OK'),
              ),
            ],
          );
        });
  switch (option) {
    case Action.OK:
      setState(() {
        _chonse = 'OK';
      });
      break;
    case Action.CANCEL:
      setState(() {
        _chonse = 'CANCEL';
      });
      break;
 ;
  }

  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('AlertDialogDemo'),
        elevation: 0,
      ),
      body: Container(
        padding: EdgeInsets.all(16),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text('lll$_chonse'),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                ElevatedButton(
                  onPressed: _open,
                  child: Text(
                    'button',
                  ),
                ),
              ],
            )
          ],
        ),
      ),
    );
  }
}
